import pygame
from pygame.sprite import Sprite

class Alien_bullet(Sprite):
    """管理外星人子弹的类"""

    def __init__(self, ai_game):
        super().__init__()
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        self.color = self.settings.aline_bullet_color

        # 创建子弹的矩形再将其改到正确的位置
        self.rect = pygame.Rect(0, 0, self.settings.bullet_width, self.settings.bullet_height)
        self.rect.midbottom = ai_game.aline.rect.midbottom

        # 用浮点数表示子弹的位置
        self.y = float(self.rect.y)

    def update(self):
        """向下移动子弹"""
        self.y += self.settings.aline_bullet_speed
        self.rect.y = self.y

    def draw_alien_bullet(self):
        """绘制子弹"""
        pygame.draw.rect(self.screen, self.color, self.rect)